package com.xkstream.client.ui.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.xkstream.client.R;
import com.xkstream.client.entity.ReceiveGift;
import com.xkstream.client.utils.AsyncImage;
import com.xkstream.client.utils.LogUtil;

import java.util.List;

/**
 * Created by admin on 2017/3/29.
 */

public class ReceiveGiftRankAdapter extends BaseAdapter{
    List<ReceiveGift> list ;
    Context context ;
    public ReceiveGiftRankAdapter(Context context ,List<ReceiveGift> list ){
        this.list = list ;
        this.context = context ;
    }
    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if(convertView == null){
            holder = new ViewHolder();
            convertView = View.inflate(context, R.layout.layout_receivegiftnum_item,null);
            holder.ivContribution = (ImageView)convertView.findViewById(R.id.ivContribution);
            holder.ivHeader = (ImageView)convertView.findViewById(R.id.ivHeader);
            holder.tvName = (TextView)convertView.findViewById(R.id.tvName);
            convertView.setTag(holder);
        }else{
            holder = (ViewHolder) convertView.getTag();
        }
        ReceiveGift receiveGift = list.get(position);
//        holder.tvKind.setText(receiveGift.getGift_name());
//        holder.tvNum.setText(receiveGift.getGift_number());
//        holder.tvPrice.setText(receiveGift.getGift_value());
        holder.tvName.setText(receiveGift.getNickname());
            AsyncImage.loadPhoto(context,receiveGift.getHead_icon(),holder.ivHeader);
        if(position == 0||position == 1||position == 2){
            holder.ivContribution.setVisibility(View.VISIBLE);
        }else{
            holder.ivContribution.setVisibility(View.INVISIBLE);
        }
        if(position == 0){
            holder.ivContribution.setImageDrawable(context.getResources().getDrawable(R.drawable.contribution_first));
        }else if(position == 1){
            holder.ivContribution.setImageDrawable(context.getResources().getDrawable(R.drawable.contribution_second));
        }else if(position == 2){
            holder.ivContribution.setImageDrawable(context.getResources().getDrawable(R.drawable.contribution_third));
        }
        return convertView;
    }

    private class ViewHolder{
        ImageView ivContribution;
        ImageView ivHeader;
        TextView tvName;
    }
}
